<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<%request.setCharacterEncoding("utf-8");%>
<% String id = request.getParameter("stuid");%>
<% String stuName = request.getParameter("stuname"); %>
<% String stuBirthday = request.getParameter("stubirthday");%>
<% String stuClass = request.getParameter("stuclass");%>
<html>
<head>
    <title>Insert title here</title>
    <%
        Connection conn;
        Statement st;
        ResultSet rs;
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/studb?useSSL=false&serverTimezone=UTC";
        conn = DriverManager.getConnection(url, "root", "123456");
        st = conn.createStatement();
        String sql =
                "INSERT into studb(number, name,birthday, stuclass) VALUES('"+id+"','"+stuName+"','"+stuBirthday+"','"+stuClass+"')";
        int result = st.executeUpdate(sql);
        if (result > 0)
            out.print("  <script type='text/javascript'>alert('添加成功'); </script> ");
        else
            out.print("  <script type='text/javascript'>alert('添加失败'); </script> ");
//  sql = "select * from studb ";
        sql = "select * from studb ";
        rs = st.executeQuery(sql);


    %>
</head>
<body>
<table border="1">
    <tr>
        <th colspan="4" align="center"> 学生信息表</th>
    </tr>
    <tr style=" text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>生日</td>
        <td>班级</td>
    </tr>

    <% while (rs.next()) { %>
    <tr style=" text-align: center">
        <td><%= rs.getString(1)%>
        </td>
        <td><%= rs.getString(2)%>
        </td>
        <td><%= rs.getString(3)%>
        </td>
        <td><%= rs.getString(4)%>
        </td>
    </tr>
    <% } %>
</table>
<%
    rs.close();
    st.close();
    conn.close();
%>
</body>
</html>